package hng.controller;


import hng.service.ProductService;
import hng.util.JsonData;
import hng.vo.ProductCommentVO;
import hng.vo.ProductDetailVO;
import hng.vo.ProductVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 告白
 * @since 2024-06-27
 */
@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired(required = false)
    private ProductService productService;

    private static final Integer TOP_BUY_NUM = 6;//看了又看展示的商品数

    private static final Integer TOP_NUM = 6;//猜你喜欢展示的商品数

    /**
     * 模糊搜索商品
     */
    @GetMapping("/search")
    public JsonData search(@RequestParam("keyword") String keyword) {
        List<ProductVO> productVOList = productService.search(keyword);
        return JsonData.buildSuccess(productVOList);
    }

    /**
     * 通过分类id查找商品列表
     */
    @GetMapping("/search-category")
    public JsonData searchCategory(@RequestParam("categoryId") Integer categoryId) {
        List<ProductVO> productVOList = productService.searchCategory(categoryId);
        return JsonData.buildSuccess(productVOList);
    }

    /**
     * 查看商品详情
     */
    @GetMapping("/detail")
    public JsonData detail(@RequestParam("productId") Integer productId) {
        ProductDetailVO productDetailVO = productService.detail(productId);
        return JsonData.buildSuccess(productDetailVO);
    }

    /**
     * 获取评论列表
     */
    @GetMapping("/comment-list")
    public JsonData commentList(@RequestParam("productId") Integer productId) {
        List<ProductCommentVO> commentList = productService.commentList(productId);
        return JsonData.buildSuccess(commentList);
    }
    /**
     * 看了又看（销量前6）
     */
    @GetMapping("/top-selling-products")
    public JsonData topSellingProducts(){
        List<ProductVO> topSellingProducts = productService.getTopSellingProducts(TOP_BUY_NUM);
        return JsonData.buildSuccess(topSellingProducts);
    }

    /**
     * 猜你喜欢（id前6）
     */
    @GetMapping("/top-products")
    public JsonData topProducts(){
        List<ProductVO> topProducts = productService.getTopProducts(TOP_NUM);
        return JsonData.buildSuccess(topProducts);
    }





}

